home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Classes / RCString / archt.m next >
Text File  |  1995-06-12  |  1KB  |  63 lines

  1. // testing of cheesy file descriptor type
  2. // object archiving.
  3. #import <stdio.h>
  4. #import <stdlib.h>
  5. #import <signal.h>
  6. #import <fcntl.h>
  7. #import <string.h>
  8. #import <sys/time.h>
  9. #import <RCString.h>
  10.  
  11. int
  12. main(int c, char **v)
  13. {
  14.     RCString *oString, *oString2;
  15.  
  16.     // cmd string1 string2 archive_file_name
  17.     if (c != 4) {
  18.         fprintf(stderr, "usage: %s string1 string2 archive_file_name\n", *v);
  19.         exit(1);
  20.     }
  21.  
  22.     oString = [RCString newFromString:v[1]];
  23.     oString2 = [RCString newFromString:v[2]];
  24.     if (oString && oString2) {
  25.  
  26.         char bvBuf[1024];
  27.         int iArchiveFD = open(*(v + 3), O_RDWR|O_CREAT, 0666);
  28.         if (iArchiveFD < 0) {
  29.             perror("opening archive file");
  30.             exit(2);
  31.         }
  32.  
  33. #ifdef NeXT
  34.         printf("first RCString object in class \"%s\"\n", [oString name]);
  35. #endif
  36.  
  37.         printf("string 1: \"%s\"\n", [oString  data]);
  38.         printf("string 2: \"%s\"\n", [oString2 data]);
  39.  
  40.         [oString storeOn:iArchiveFD];
  41.         if (lseek(iArchiveFD, 0, L_SET) >= 0) {
  42.             // seeked back to start of file.  Read in object.
  43.             [oString2 readFrom:iArchiveFD];
  44.         } else {
  45.             // seek failed
  46.             perror("seeking in archive file after object write");
  47.         }
  48.  
  49.         printf("after de-archiving:\n");
  50.         printf("string 1: \"%s\"\n", [oString  data]);
  51.         printf("string 2: \"%s\"\n", [oString2 data]);
  52.  
  53.         [oString  free];
  54.         [oString2 free];
  55.         close(iArchiveFD);
  56.         gets(bvBuf); // pause for check of file, etc.
  57.     } else {
  58.         fprintf(stderr, "newFromString: failure\n");
  59.         return(1);
  60.     }
  61.     return(0);
  62. }
  63.